/**
 * @description 新闻及新闻分类表
 */

const mongoose = require("../db/mongoose");
const newsCategorySchema = mongoose.Schema(
  {
    name: String,
  },
  { timestamps: true }
);
const newsSchema = mongoose.Schema(
  {
    // 新闻分类id
    cId: String,
    // 新闻名称
    title: String,
    // 发布者
    authorName: {
      type: String,
      default: "admin",
    },
    // 新闻内容html
    content: String,
    // 最后发布时间
    latestPublishAt: {
      type: Date,
      default: new Date(),
    },
    //新闻访问量
    pageView: {
      type: Number,
      default: 0,
    },
  },
  { timestamps: true }
);

// 新闻模块
const NewsCategoryModel = mongoose.model("newsCategory", newsCategorySchema);
const NewsModel = mongoose.model("new", newsSchema);

module.exports = {
  NewsModel,
  NewsCategoryModel,
};
